<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="单据编号">
              <a-input placeholder="请输入单据编号" v-model="queryParam.billNo"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-model-item label="还款人">
              <select-user-by-dep
                placeholder="请选择还款人"
                v-model="queryParam.proposer" />
            </a-form-model-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="申请公司">
              <select-Company-input  v-model="queryParam.applyCompany" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="所属团队">
              <select-team-input placeholder="请选择所属团队"  v-model="queryParam.teamId" :teamType="0" :tdlx="3" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="还款时间">
              <a-range-picker
              :allowClear="false"
              v-model="createTime"
              style="width: 100%"
              @change="createTimeChange"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="handleExportXls('还款申请清单')">导出</a-button>
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item,index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12" :key="index"><a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox></a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a-row>
          <a-col>
            <a style="float: right;"><a-icon type="setting" :style='iconStyle'/></a>
          </a-col>
        </a-row>
      </a-popover>
    </div>
    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:scrollX}"
        :components="draggableComponent"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        :customRow="customRow"
        @change="handleTableChange">
        <a slot="billNo" slot-scope="text, record" @click="getDetail(record.id)">{{ text }}</a>
        <template slot="status" slot-scope="status">
          <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <span slot="action" slot-scope="text, record">
            <template v-if="record.bpmStatus === '1'">
            <a-button
                    class="ruleButton"
                    :ghost="true"
                    type="primary"
                    icon="edit"
                    @click="handleEdit(record)"
                    :disabled="isDisabledAuth('erpFinanceRepaymentSlip:edit')"
            />
            <a-divider type="vertical"/>
            <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                <a-button
                        class="ruleButton"
                        :ghost="true"
                        type="primary"
                        icon="delete"
                        :disabled="isDisabledAuth('erpFinanceRepaymentSlip:delete')"/>
            </a-popconfirm>
            <a-divider type="vertical"/>
            <a-button type="primary" size="small" @click="startProcess(record)" :disabled="isDisabledAuth('erpFinanceRepaymentSlip:startProcess')">发起流程</a-button>
        </template>
        <template v-else-if="showBtn(record.bpmStatus)&&queryParam.bizTaskType=='1'">
            <a-button type="primary" size="small" @click="handleProcess(record)">办理</a-button>
            <a-divider type="vertical"/>
        </template>
        <template v-else-if="queryParam.bizTaskType=='2' && showBtn(record.bpmStatus)">
            <a-button type="primary" size="small" @click="taskNotify(flowCode,record.id)">催办</a-button>
            <a-divider type="vertical"/>
            <a-popconfirm title="确定要作废吗?" @confirm="() => invalidProcess(record)">
                <a-button type="primary" size="small" :disabled="isDisabledAuth('erpFinanceRepaymentSlip:invalidProcess')">
                    作废流程
                </a-button>
            </a-popconfirm>
            <a-divider type="vertical"/>
        </template>
        <template v-if="record.bpmStatus !== '1'">
            <a-button type="primary" size="small" @click="handleTrack(record)" :disabled="isDisabledAuth('erpFinanceRepaymentSlip:viewTrack')">审批进度</a-button>
        </template>
        </span>
      </a-table>
    </div>
    <erp-finance-repayment-slip-modal ref="modalForm" @ok="modalFormOk"></erp-finance-repayment-slip-modal>
    <bpm-biz-task-deal-modal ref="taskDealModal" :path="path" :formData="formData" @ok="handleOk"></bpm-biz-task-deal-modal>
    <bpm-process-track-modal ref="bpmProcessTrackModal"></bpm-process-track-modal>
    <biz-task-notify-modal ref="taskNotifyModal"></biz-task-notify-modal>
    <biz-task-notify-me-modal ref="taskNotifyMeModal"></biz-task-notify-me-modal>
  </a-card>
</template>
<script>
  import '@/assets/less/TableExpand.less';
  import { mixinDevice } from '@/utils/mixin'
  import {JeecgBpmListMixin} from '@/mixins/JeecgBpmListMixin'
  import ErpFinanceRepaymentSlipModal from './modules/ErpFinanceRepaymentSlipModal';
  import {DisabledAuthFilterMixin} from '@/mixins/DisabledAuthFilterMixin';
  import SelectProjectInput from '@/views/scy/components/SelectProjectInput';
  import SelectTeamInput from '@/views/scy/components/SelectTeamInput';
  import { filterMultiDictText, initDictOptions } from '@/components/dict/JDictSelectUtil';
  import BpmBizTaskDealModal from "@/views/modules/bpmbiz/common/BpmBizTaskDealModal";
  import BpmProcessTrackModal from "@/views/modules/bpmbiz/common/BpmProcessTrackModal";
  import BizTaskNotifyModal from "@/views/modules/bpmbiz/common/BizTaskNotifyModal";
  import BizTaskNotifyMeModal from "@/views/modules/bpmbiz/common/BizTaskNotifyMeModal";
  import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
  import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput'
  export default {
    name: 'ErpFinanceRepaymentSlipList',
    mixins:[JeecgBpmListMixin, mixinDevice, DisabledAuthFilterMixin],
    components: {
      ErpFinanceRepaymentSlipModal,
      SelectProjectInput,
      SelectTeamInput,
      BpmBizTaskDealModal,
      BpmProcessTrackModal,
      BizTaskNotifyModal,
      BizTaskNotifyMeModal,
      SelectUserByDep,
      SelectCompanyInput
    },
    data () {
      return {
        description: '还款单管理页面',
        //表头
        columns:[],
        //列设置
        settingColumns:[],
        // 列定义
        defColumns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'单据编号',
            align:"center",
            dataIndex: 'billNo',
            scopedSlots: { customRender: 'billNo' },
            width:230,
            ellipsis: true,
          },
          {
            title:'申请部门',
            align:"center",
            dataIndex: 'proposerDeptId_dictText',
            width:150,
            ellipsis: true,
          },
          {
            title:'还款人',
            align:"center",
            dataIndex: 'proposer_dictText',
            width:110,
            ellipsis: true,
          },
          {
            title:'申请公司',
            align:"center",
            dataIndex: 'applyCompany_dictText',
            width:350,
            ellipsis: true,
          },
          {
            title:'所属团队',
            align:"center",
            dataIndex: 'teamId_dictText',
            width:230,
            ellipsis: true,
          },
          {
            title:'还款时间',
            align:"center",
            dataIndex: 'createTime',
            width:230,
            ellipsis: true,
          },
          {
            title:'本次累计还款金额（元）',
            align:"center",
            dataIndex: 'repaymentAmount',
            width:210,
            ellipsis: true,
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:150,
            scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action' }
          }
        ],
        url: {
          list: "/api/erp/finance/repayment/erpFinanceRepaymentSlip/checkList",
          delete: "/api/erp/finance/repayment/erpFinanceRepaymentSlip/delete",
          deleteBatch: "/api/erp/finance/repayment/erpFinanceRepaymentSlip/deleteBatch",
          exportXlsUrl: "/api/erp/finance/repayment/erpFinanceRepaymentSlip/inventoryExportXls",
          importExcelUrl: "api/erpfinance/repayment/erpFinanceRepaymentSlip/importExcel",
          submit: "/api/erp/finance/repayment/erpFinanceRepaymentSlip/submit",
          submitBatch: "/api/erp/finance/repayment/erpFinanceRepaymentSlip/submitBatch",
          revoke: "/api/erp/finance/repayment/erpFinanceRepaymentSlip/revoke",
          revokeBatch: "/api/erp/finance/repayment/erpFinanceRepaymentSlip/revokeBatch",
          counterTrial: "/api/erp/finance/repayment/erpFinanceRepaymentSlip/counterTrial",
          counterTrialBatch: "/api/erp/finance/repayment/erpFinanceRepaymentSlip/counterTrialBatch",
          audit: "/api/erp/finance/repayment/erpFinanceRepaymentSlip/audit",
          auditBatch: "/api/erp/finance/repayment/erpFinanceRepaymentSlip/auditBatch",
          overrule: "/api/erp/finance/repayment/erpFinanceRepaymentSlip/overrule",
          overruleBatch: "/api/erp/finance/repayment/erpFinanceRepaymentSlip/overruleBatch",
        },
        dictOptions:{},
        superFieldList:[],
        createTime: [],
        flowCode: 'onl_erp_finance_repayment_slip',
        formUrl: "/erp/finance/repayment/modules/ErpFinanceRepaymentSlipForm",
        formUrlMobile: "",
        processId:"",
        beanName: 'erpFinanceRepaymentSlipServiceImpl',
      }
    },
    created() {
      this.getSuperFieldList();
      //加载数据字典信息
      this.initDictConfig();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      //流程审批结束禁用
      getCheckboxProps(record) {
        console.log(record);
        return {
          props: {
            disabled: record.bpmStatus !== "1"
          }
        }
      },
      //查看详情
      getDetail(id) {
        this.$router.push({
          path: `/erp/finance/repayment/ErpFinanceRepaymentSlipListDetail/${id}`,
        })
      },
      // table 双击查看详情
      customRow(record) {
        return {
          on: {
            // 事件
            dblclick: event => {
              this.$router.push({
                path: `/erp/finance/repayment/ErpFinanceRepaymentSlipListDetail/${record.id}`
              })
            }
          }
        }
      },
      createTimeChange(date, dateString) {
        this.$set(this.queryParam, 'createStartTime', dateString[0] + ' 00:00:00')
        this.$set(this.queryParam, 'createEndTime', dateString[1] + ' 23:59:59')
      },
      searchReset() {
        this.createTime = []
        this.queryParam = {}
        this.loadData(1)
      },
      initDictConfig(){
        initDictOptions('erp_omc_project,project_name,id').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'projectId', res.result)
          }
        })
        initDictOptions('erp_omc_prepare_project,mc,id').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'preprojectId', res.result)
          }
        })
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'billNo',text:'单据编号',dictCode:''})
        fieldList.push({type:'string',value:'proposer',text:'还款人',dictCode:''})
        fieldList.push({type:'date',value:'createTime',text:'还款时间'})
        fieldList.push({type:'int',value:'repaymentAmount',text:'本次累计还款金额（元）',dictCode:''})
        fieldList.push({type:'string',value:'bpmStatus',text:'流程状态',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
